-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-120198: Stop the world when setting __class__ on free-threaded build #120672
gh-120198: Stop the world when setting __class__ on free-threaded build #120672
Conversation
Fidget-Spinner
commented
Jun 18, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Read and write of __class__ in two threads causes crash #120198
Objects/typeobject.c
Outdated
} | ||
err: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To have a more regular try: ... finally: _PyEval_StartTheWorld()
pattern, you can add an int res = -1;
variable, replace goto err
with goto done
, and set res to 0
on success (3 lines above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @vstinner's suggestion is fine. Or you can refactor the parts that should be in a stop-the-world call into it's own function, like we often do for locks.
Another advantage of moving the body to a separate function is that it makes it more clear what data crosses the stop-the-world boundary -- some data loaded before the stop-the-world call may not be valid after it.
Include/internal/pycore_dict.h
Outdated
@@ -323,6 +323,8 @@ _PyInlineValuesSize(PyTypeObject *tp) | |||
int | |||
_PyDict_DetachFromObject(PyDictObject *dict, PyObject *obj); | |||
|
|||
PyDictObject *_PyObject_materialize_managed_dict_lock_held(PyObject *); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name this like the other functions: _PyObject_MaterializeManagedDict_LockHeld
and move the definition up next to _PyObject_MaterializeManagedDict
.
Objects/typeobject.c
Outdated
} | ||
err: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @vstinner's suggestion is fine. Or you can refactor the parts that should be in a stop-the-world call into it's own function, like we often do for locks.
Another advantage of moving the body to a separate function is that it makes it more clear what data crosses the stop-the-world boundary -- some data loaded before the stop-the-world call may not be valid after it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few comments about comments.
I think this should be backported to 3.13
Thanks @Fidget-Spinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @Fidget-Spinner, I could not cleanly backport this to
|